unit Actions;

interface

uses
  Models,
  Windows, Forms, Types, SysUtils, ShlObj, ComObj, ShellAPI, ActiveX;

procedure SetCommandMode(Form: IMainForm);
procedure SetSelectMode(Form: IMainForm);

procedure NewFileList(Form: IMainForm; PathName, Command: WideString;
                      FileCount: Integer);
procedure AddFile(Form: IMainForm; FileName: WideString; TextletCount: Integer);
procedure AddFileTextlet(Form: IMainForm; Level, Left, Width, Font: Integer; Text: WideString);
procedure CommitFileList(Form: IMainForm);

procedure NewSkin (Form: IMainForm; col, scol, hcnt, fcnt: Integer);
procedure AddItemHeight (Form: IMainForm; h: Integer);
procedure AddFont (Form: IMainForm; name: WideString; size: Integer;
                   style, pitch: WideString; color, charset: Integer); 
procedure CommitSkin (Form: IMainForm);

procedure Close(Form: IMainForm);

procedure Up(Form: IMainForm; Step: Integer);
procedure Down(Form: IMainForm; Step: Integer);

procedure ToggleSelection(Form: IMainForm; Index: Integer);
procedure SelectAll(Form: IMainForm);
procedure UnselectAll(Form: IMainForm);

procedure ContextMenu(Form: IMainForm);
procedure DragDropContextMenu(Form: IMainForm);
procedure DragStart(Form: IMainForm);
procedure SetDragDropEffect(Form: IMainForm; dwEffect: Integer);

implementation

uses
  LishModl, Skin;

procedure SetCommandMode(Form: IMainForm);
  begin
    Form.FileList.ItemIndex := Form.FileView.ItemIndex;
    Form.CmdView.SetFocus;
    Form.CmdView.SelStart := Length(Form.CmdView.Text);
  end;

procedure SetSelectMode(Form: IMainForm);
  begin
    Form.FileView.SetFocus;
    Form.FileView.ItemIndex := Form.FileList.ItemIndex;
  end;

procedure NewFileList(Form: IMainForm; PathName, Command: WideString;
                      FileCount: Integer);
  var FL: TFileList;
  begin
    FL := TFileList.Create(PathName, Command, FileCount);
    Form.SetFileList(FL);
  end;

procedure AddFile(Form: IMainForm; FileName: WideString; TextletCount: Integer);
  begin
    Form.FileList.AddFile(FileName, TextletCount);
  end;

procedure AddFileTextlet(Form: IMainForm; Level, Left, Width, Font: Integer; Text: WideString);
  begin
    Form.FileList.AddTextlet(Level, Left, Width, Font, Text);
  end;

procedure CommitFileList(Form: IMainForm);
  begin
    Form.FileList.Commit;
    Form.CommitFileList;
  end;

procedure NewSkin (Form: IMainForm; col, scol, hcnt, fcnt: Integer);
  var Skin: TSkin;
  begin
    Skin := TSkin.Create(col, scol, hcnt, fcnt);
    Form.SetSkin(Skin);
  end;

procedure AddItemHeight (Form: IMainForm; h: Integer);
  begin
    Form.Skin.AddItemHeight(h);
  end;

procedure AddFont (Form: IMainForm; name: WideString; size: Integer;
                   style, pitch: WideString; color, charset: Integer);
  begin
    Form.Skin.AddFont(name, size, style, pitch, color, charset);
  end;

procedure CommitSkin (Form: IMainForm);
  begin
    Form.Skin.Commit;
  end;

procedure Close(Form: IMainForm);
  begin
    Form.Close;
  end;

procedure Up(Form: IMainForm; Step: Integer);
  var next: Integer;
  begin
    with Form.FileView do begin
      if Count <= 0 then Exit;
      next := ItemIndex - Step;
      if next < 0 then next := 0;
      if ItemIndex <> next then begin
        ItemIndex := next;
        Refresh;
      end;
    end;
  end;

procedure Down(Form: IMainForm; Step: Integer);
  var next: Integer;
  begin
    with Form.FileView do begin
      if Count <= 0 then Exit;
      next := ItemIndex + 1;
      if next >= Count then next := Count - 1;
      if ItemIndex <> next then begin
        ItemIndex := next;
        Refresh;
      end;
    end;
  end;

procedure ToggleSelection(Form: IMainForm; Index: Integer);
  begin
    if (Index >= 0) and (Index < Form.FileList.Count) then begin
      Form.FileList.Selected[Index]
        := not Form.FileList.Selected[Index];
      Form.FileView.Refresh;
    end;
  end;

procedure SelectAll(Form: IMainForm);
  var I: Integer;
  begin
    for I := 0 to Form.FileList.Count - 1 do begin
      Form.FileList.Selected[I] := True;
    end;
    Form.FileView.Refresh;
  end;

procedure UnselectAll(Form: IMainForm);
  var I: Integer;
  begin
    for I := 0 to Form.FileList.Count - 1 do begin
      Form.FileList.Selected[I] := False;
    end;
    Form.FileView.Refresh;
  end;

procedure ContextMenu(Form: IMainForm);
  begin
    Form.ContextMenu;
  end;

procedure DragDropContextMenu(Form: IMainForm);
  begin
    Form.DragDropContextMenu;
  end;

procedure DragStart(Form: IMainForm);
  begin
    Form.DragStart;
  end;

procedure SetDragDropEffect(Form: IMainForm; dwEffect: Integer);
  begin
    Form.SetDragDropEffect(dwEffect);
  end;

end.
